42 #define CORRUPTMATRIX 0.001F // column vector modulus limit for rotation matrix 50 for (i = 0; i < 3; i++)
54 for (j = 0; j < 3; j++)
72 for (i = 0; i < 3; i++)
77 for (j = 0; j < 3; j++)
79 *(pAij++) = *(pBij++);
93 for (i = 0; i < rc; i++)
97 for (j = 0; j < rc; j++)
114 for (i = 0; i < 3; i++)
118 for (j = 0; j < 3; j++)
133 for (i = 0; i < 3; i++)
137 for (j = 0; j < 3; j++)
152 for (i = 0; i < 3; i++)
156 for (j = 0; j < 3; j++)
170 float fB11B22mB12B12;
171 float fB12B02mB01B22;
172 float fB01B12mB11B02;
176 fB11B22mB12B12 = B[1][1] * B[2][2] - B[1][2] * B[1][2];
177 fB12B02mB01B22 = B[1][2] * B[0][2] - B[0][1] * B[2][2];
178 fB01B12mB11B02 = B[0][1] * B[1][2] - B[1][1] * B[0][2];
192 A[0][0] = fB11B22mB12B12 * ftmp;
193 A[1][0] = A[0][1] = fB12B02mB01B22 * ftmp;
194 A[2][0] = A[0][2] = fB01B12mB11B02 * ftmp;
195 A[1][1] = (B[0][0] * B[2][2] - B[0][2] * B[0][2]) * ftmp;
196 A[2][1] = A[1][2] = (B[0][2] * B[0][1] - B[0][0] * B[1][2]) * ftmp;
197 A[2][2] = (B[0][0] * B[1][1] - B[0][1] * B[0][1]) * ftmp;
223 (A[CHY][
CHX] * A[CHZ][CHY] - A[CHY][CHY] * A[CHZ][
CHX])
237 #define NITERATIONS 15 262 for (i = 0; i < n; i++)
265 for (j = 0; j < n; j++)
286 for (i = 0; i < n - 1; i++)
289 for (j = i + 1; j < n; j++)
292 residue += fabsf(A[i][j]);
300 for (i = 0; i < n - 1; i++)
303 for (j = i + 1; j < n; j++)
306 if (fabsf(A[i][j]) > 0.0F)
309 cot2phi = 0.5F * (eigval[j] - eigval[i]) / (A[i][j]);
312 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
319 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
320 sinphi = tanphi * cosphi;
323 tanhalfphi = sinphi / (1.0F + cosphi);
326 ftmp = tanphi * A[i][j];
339 for (k = 0; k < n; k++)
345 eigvec[k][i] = ftmp - sinphi * (eigvec[k][j] + tanhalfphi * ftmp);
348 eigvec[k][j] = eigvec[k][j] + sinphi * (ftmp - tanhalfphi * eigvec[k][j]);
352 for (k = 0; k <= i - 1; k++)
358 A[k][i] = ftmp - sinphi * (A[k][j] + tanhalfphi * ftmp);
361 A[k][j] = A[k][j] + sinphi * (ftmp - tanhalfphi * A[k][j]);
364 for (k = i + 1; k <= j - 1; k++)
370 A[i][k] = ftmp - sinphi * (A[k][j] + tanhalfphi * ftmp);
373 A[k][j] = A[k][j] + sinphi * (ftmp - tanhalfphi * A[k][j]);
376 for (k = j + 1; k < n; k++)
382 A[i][k] = ftmp - sinphi * (A[j][k] + tanhalfphi * ftmp);
385 A[j][k] = A[j][k] + sinphi * (ftmp - tanhalfphi * A[j][k]);
391 }
while ((residue > 0.0F) && (ctr++ <
NITERATIONS));
410 #define NITERATIONS 15 435 for (ir = 0; ir < n; ir++)
438 for (ic = 0; ic < n; ic++)
441 eigvec[ir][ic] = 0.0F;
445 eigvec[ir][ir] = 1.0F;
448 eigval[ir] = A[ir][ir];
459 for (ir = 0; ir < n - 1; ir++)
462 for (ic = ir + 1; ic < n; ic++)
465 residue += fabsf(A[ir][ic]);
473 for (ir = 0; ir < n - 1; ir++)
476 for (ic = ir + 1; ic < n; ic++)
479 if (fabsf(A[ir][ic]) > 0.0F)
483 (eigval[ic] - eigval[ir]) /
487 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
494 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
495 sinphi = tanphi * cosphi;
498 tanhalfphi = sinphi / (1.0F + cosphi);
501 ftmp = tanphi * A[ir][ic];
514 for (j = 0; j < n; j++)
517 ftmp = eigvec[j][ir];
520 eigvec[j][ir] = ftmp - sinphi * (eigvec[j][ic] + tanhalfphi * ftmp);
523 eigvec[j][ic] = eigvec[j][ic] + sinphi * (ftmp - tanhalfphi * eigvec[j][ic]);
527 for (j = 0; j <= ir - 1; j++)
533 A[j][ir] = ftmp - sinphi * (A[j][ic] + tanhalfphi * ftmp);
536 A[j][ic] = A[j][ic] + sinphi * (ftmp - tanhalfphi * A[j][ic]);
539 for (j = ir + 1; j <= ic - 1; j++)
545 A[ir][j] = ftmp - sinphi * (A[j][ic] + tanhalfphi * ftmp);
548 A[j][ic] = A[j][ic] + sinphi * (ftmp - tanhalfphi * A[j][ic]);
551 for (j = ic + 1; j < n; j++)
557 A[ir][j] = ftmp - sinphi * (A[ic][j] + tanhalfphi * ftmp);
560 A[ic][j] = A[ic][j] + sinphi * (ftmp - tanhalfphi * A[ic][j]);
566 }
while ((residue > 0.0F) && (ctr++ <
NITERATIONS));
584 cot2phi = 0.5F * (fvecA[j] - fvecA[i]) / (fmatA[i][j]);
587 tanphi = 1.0F / (fabsf(cot2phi) + sqrtf(1.0F + cot2phi * cot2phi));
588 if (cot2phi < 0.0F) tanphi = -tanphi;
591 cosphi = 1.0F / sqrtf(1.0F + tanphi * tanphi);
592 sinphi = tanphi * cosphi;
595 tanhalfphi = sinphi / (1.0F + cosphi);
598 ftmp = tanphi * fmatA[i][j];
611 for (k = 0; k < iMatrixSize; k++)
617 fmatB[k][i] = ftmp - sinphi * (fmatB[k][j] + tanhalfphi * ftmp);
620 fmatB[k][j] = fmatB[k][j] + sinphi * (ftmp - tanhalfphi * fmatB[k][j]);
624 for (k = 0; k <= i - 1; k++)
630 fmatA[k][i] = ftmp - sinphi * (fmatA[k][j] + tanhalfphi * ftmp);
633 fmatA[k][j] = fmatA[k][j] + sinphi * (ftmp - tanhalfphi * fmatA[k][j]);
636 for (k = i + 1; k <= j - 1; k++)
642 fmatA[i][k] = ftmp - sinphi * (fmatA[k][j] + tanhalfphi * ftmp);
645 fmatA[k][j] = fmatA[k][j] + sinphi * (ftmp - tanhalfphi * fmatA[k][j]);
648 for (k = j + 1; k < iMatrixSize; k++)
654 fmatA[i][k] = ftmp - sinphi * (fmatA[j][k] + tanhalfphi * ftmp);
657 fmatA[j][k] = fmatA[j][k] + sinphi * (ftmp - tanhalfphi * fmatA[j][k]);
682 iPivotRow = iPivotCol = 0;
688 for (j = 0; j < isize; j++)
694 for (i = 0; i < isize; i++)
700 for (j = 0; j < isize; j++)
706 for (k = 0; k < isize; k++)
712 if (fabsf(A[j][k]) >= largest)
717 largest = (float) fabsf(A[iPivotRow][iPivotCol]);
720 else if (iPivot[k] > 1)
735 if (iPivotRow != iPivotCol)
738 for (l = 0; l < isize; l++)
741 ftmp = A[iPivotRow][l];
742 A[iPivotRow][l] = A[iPivotCol][l];
743 A[iPivotCol][l] = ftmp;
748 iRowInd[i] = iPivotRow;
749 iColInd[i] = iPivotCol;
752 if (A[iPivotCol][iPivotCol] == 0.0F)
761 recippiv = 1.0F / A[iPivotCol][iPivotCol];
764 A[iPivotCol][iPivotCol] = 1.0F;
768 for (l = 0; l < isize; l++)
770 if (A[iPivotCol][l] != 0.0F) A[iPivotCol][l] *= recippiv;
774 for (m = 0; m < isize; m++)
779 scaling = A[m][iPivotCol];
782 A[m][iPivotCol] = 0.0F;
785 for (l = 0; l < isize; l++)
787 if ((A[iPivotCol][l] != 0.0F) && (scaling != 0.0F))
788 A[m][l] -= A[iPivotCol][l] * scaling;
795 for (l = isize - 1; l >= 0; l--)
805 for (k = 0; k < isize; k++)
820 void fveqRu(
float fv[],
float fR[][3],
float fu[],
int8 itranspose)
void fmatrixAeqInvA(float *A[], int8 iColInd[], int8 iRowInd[], int8 iPivot[], int8 isize, int8 *pierror)
function uses Gauss-Jordan elimination to compute the inverse of matrix A in situ on exit...
#define CHY
Used to access Y-channel entries in various data data structures.
void f3x3matrixAeqB(float A[][3], float B[][3])
function sets 3x3 matrix A to 3x3 matrix B
void f3x3matrixAeqMinusA(float A[][3])
function negates all elements of 3x3 matrix A
void f3x3matrixAeqAxScalar(float A[][3], float Scalar)
function multiplies all elements of 3x3 matrix A by the specified scalar
float f3x3matrixDetA(float A[][3])
function calculates the determinant of a 3x3 matrix
void fmatrixAeqI(float *A[], int16 rc)
function sets the matrix A to the identity matrix
void fEigenCompute10(float A[][10], float eigval[], float eigvec[][10], int8 n)
function computes all eigenvalues and eigenvectors of a real symmetric matrix A[0..n-1][0..n-1] stored in the top left of a 10x10 array A[10][10]
The sensor_fusion.h file implements the top level programming interface.
void fVeq3x3AxV(float V[3], float A[][3])
function multiplies the 3x1 vector V by a 3x3 matrix A
void f3x3matrixAeqInvSymB(float A[][3], float B[][3])
function directly calculates the symmetric inverse of a symmetric 3x3 matrix only the on and above di...
Matrix manipulation functions.
void fComputeEigSlice(float fmatA[10][10], float fmatB[10][10], float fvecA[10], int8 i, int8 j, int8 iMatrixSize)
void fEigenCompute4(float A[][4], float eigval[], float eigvec[][4], int8 n)
function computes all eigenvalues and eigenvectors of a real symmetric matrix A[0..n-1][0..n-1] stored in the top left of a 4x4 array A[4][4] A[][] is changed on output. The eigenvectors are not sorted by value. This function is identical to eigencompute10 except for the workaround for 4x4 matrices since C cannot handle functions accepting matrices with variable numbers of columns.
#define CHX
Used to access X-channel entries in various data data structures.
void fveqRu(float fv[], float fR[][3], float fu[], int8 itranspose)
function rotates 3x1 vector u onto 3x1 vector using 3x3 rotation matrix fR. the rotation is applied i...
void f3x3matrixAeqI(float A[][3])
function sets the 3x3 matrix A to the identity matrix
void f3x3matrixAeqScalar(float A[][3], float Scalar)
function sets every entry in the 3x3 matrix A to a constant scalar